#include "event/loop.hpp"
#include "fmt/core.h"
#include "network/sockaddr.hpp"
#include "network/tcp_client.hpp"

using namespace std;
using namespace ibox::event;
using namespace ibox::network;
int main() {
    SockAddr server_addr = SockAddr::from_string("127.0.0.1:8080");
    auto loop = Loop();

    // 这个例子实现的功能: 服务端回显消息(可以使用nc作为服务端), 客户端不需要输入
    TcpClient client{&loop};
    client.initialize(server_addr);
    client.bind(&client); // 绑定自己, 即实现echo
    client.start();

    if (server_addr.type() == SockAddr::Type::IPv4) {
        IpAddress ip;
        uint16_t port = 0;
        server_addr.get(ip, port);
        fmt::print("try command: nc -l -p {}\n", port);
    }
    loop.run();
    client.cleanup();
}
